﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
 }
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var date = '@ViewBag.date';
    var userid = '@ViewBag.userid';
    var deviceno = '@ViewBag.deviceno';
    $(function () {
        initGrid();
    });

    function initGrid() {
        var queryUrl = userid ? '@Url.Content("~/ScheduleManage/ScheduleUser/GetPageListJson")' + '?date=' + date + '&enddate=' + date + '&userid=' + userid
            : '@Url.Content("~/ScheduleManage/Schedule/GetPageListJson")' + '?date=' + date + '&enddate=' + date + '&deviceno=' + deviceno;
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { field: 'Id', title: 'Id', visible: false },
                { field: 'BaseCreatorName', title: '填报人' },
                { field: 'Date', title: '日期', formatter: function (value, row, index) { return new Date(value).toLocaleDateString(); } },
                { field: userid ? 'UserName' : 'DeviceName', title: userid ? '人员名称' : '设备名称' },
                { field: userid ? '' : 'DeviceNo', title: userid ? '' : '设备编号', visible: userid ? false : true },
                { field: 'ProductId', title: 'ProductId', visible: false },
                { field: 'ProductName', title: '服务项目' },
                { field: 'Count', title: '数量' },
                { field: 'AccountName', title: '客户名称' },
                { field: 'AccountAddr', title: '客户地址' },
                {
                    field: 'Id', title: '', formatter: function (value, row, index) {
                        var id = "'" + value + "'";
                        return '<a class="btn btn-danger" onclick="deleteSchedule(' + id + ')"><i class="fa fa-remove"></i> 撤销</a>';
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function deleteSchedule(id) {
        ys.confirm('确认要撤销这条日程吗？', function () {
            var url = userid ? '@Url.Content("~/ScheduleManage/ScheduleUser/DeleteFormJson")' + '?ids=' + id
                : '@Url.Content("~/ScheduleManage/Schedule/DeleteFormJson")' + '?ids=' + id;
                ys.ajax({
                    url: url,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            $('#gridTable').ysTable('search');
                            parent.searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
    }
</script>
